package com.kpmg.datalake.autopackage.utils;

import com.kpmg.datalake.common.utils.LogUtils;

import java.util.concurrent.*;

/**
 * @Author: Richard.ji [richard.ji@kpmg.com]
 * @Date: 2018-08-21 13:49:26
 * @Description:
 */
public class MyThreadPoolExecutor extends ThreadPoolExecutor {
    public MyThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit,
                                BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory);
    }

    @Override
    protected void beforeExecute(Thread t, Runnable r) {
        super.beforeExecute(t, r);
        String threadName = t.getName();

        LogUtils.info("线程" + threadName + "任务执行");
    }

    @Override
    protected void afterExecute(Runnable r, Throwable t) {
        super.afterExecute(r, t);
        String threadName = Thread.currentThread().getName();

        LogUtils.info("线程" + threadName + "任务执行结束");
    }

    @Override
    protected void terminated() {
        super.terminated();

        LogUtils.info("线程池终止");
    }
}
